$(document).ready(function(){ 
	function showError(str,delay){	
		  if(delay){
			  $('#alertMessage').removeClass('success info warning').addClass('error').html(str).stop(true,true).show().animate({ opacity: 1,right: '10'}, 500,function(){
					  $(this).delay(delay).animate({ opacity: 0,right: '-20'}, 500,function(){ $(this).hide(); });																														   																											
				});
			  return false;
		  }
			  	$('#alertMessage').addClass('error').html(str).stop(true,true).show().animate({ opacity: 1,right: '10'}, 500);	
	  }
	function showSuccess(str,delay){
		  if(delay){
			  $('#alertMessage').removeClass('error info warning').addClass('success').html(str).stop(true,true).show().animate({ opacity: 1,right: '10'}, 500,function(){
					  $(this).delay(delay).animate({ opacity: 0,right: '-20'}, 500,function(){ $(this).hide(); });																														   																											
				});
			  return false;
		  }
			  $('#alertMessage').addClass('success').html(str).stop(true,true).show().animate({ opacity: 1,right: '10'}, 500);	
	  }
	// tabs
	$('.tab_content').fadeOut();
	$("ul.tabs li").fadeIn(400); 
	$("ul.tabs li:first").addClass("active").fadeIn(400); 
	$(".tab_content:first").fadeIn(); 
	$("ul.tabs li").live('click',function() {
		  $("ul.tabs li").removeClass("active");						   
		  $(this).addClass("active");  
		  var activeTab = $(this).find("a").attr("href"); 
		  $('.tab_content').fadeOut();		
		  $(activeTab).delay(400).fadeIn();		
		  return false;
	});
	
	
	$("#create_delivery_invoice").live("click", function(){
		var list_wh = '';
		var list_re = '';
		$(".listInvoiceTransfer .WhInvoice").each(function(){
			list_wh = list_wh + $(this).attr("id").substr(0,$(this).attr("id").length - 3) + ",";
		});
		$(".listInvoiceTransfer .ReInvoice").each(function(){
			list_re = list_re + $(this).attr("id").substr(0,$(this).attr("id").length - 3) + ",";
		});
		if (list_wh == '' && list_re == ''){
			$('#uploadTab').validationEngine('showPrompt', 'Chọn hóa đơn giao hàng', 'pass','topLeft');
			showError('Chọn hóa đơn giao hàng',1000);
		}
		else{
			dataString = "list_wh=" + list_wh + "&list_re=" + list_re;
			$.ajax({
		        type: "GET",
		        url: "create_delivery_invoice",
		        data: dataString,
		        dataType: 'html',
		        success: function (data) {
		        	showSuccess('Giao hàng thành công',1000);
		        }
		    })
		}
		
	})
  })